﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Data;

namespace lxwmvc
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
    public class layoutAttribute : Attribute
    {
        public layoutAttribute(string name = "default")
        { layoutname = name; }
        public string layoutname { get; set; }
    }

    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
    public class helperAttribute : Attribute
    {
        public Type helpertype { get; set; }
        public helperAttribute(Type type)
        {
            helpertype = type;
        }

        object _instance = null;
        public object instance
        {
            get
            {
                if (_instance == null)
                    _instance = helpertype.Assembly.CreateInstance(helpertype.FullName, false);
                return _instance;
            }
        }
    }
    /// <summary>
    /// action别名
    /// </summary>
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
    public class biemingAttribute : Attribute
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        public biemingAttribute(string name = "")
        { bieming = name; }
        /// <summary>
        /// 
        /// </summary>
        public string bieming { get; set; }
    }
    /// <summary>
    /// 支持事务
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
    public class transAttribute : Attribute
    {
        /// <summary>
        /// 
        /// </summary>
        public IsolationLevel iso { get; set; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="iso"></param>
        public transAttribute(IsolationLevel iso = IsolationLevel.ReadCommitted) {
            this.iso = iso;
        }
    }

    /// <summary>
    /// 支持锁定
    /// </summary>
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
    public class tongbuAttribute : Attribute
    {
        /// <summary>
        /// 
        /// </summary>
        public bool tongbu { get; set; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="tongbu"></param>
        public tongbuAttribute(bool tongbu = true)
        {
            //锁定
            this.tongbu = tongbu;
        }
    }

    /// <summary>
    /// 输出的json对象
    /// </summary>
    public class BaseJson
    {
        /// <summary>
        /// 返回数据是否成功
        /// </summary>
        public bool success = true;
        /// <summary>
        /// 返回编码信息
        /// </summary>
        public int code = 200;
        /// <summary>
        /// 返回提示信息
        /// </summary>
        public string msg = "";
        /// <summary>
        /// 返回数据信息
        /// </summary>
        public object data = null;
    }

    /// <summary>
    /// 发送json对象
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
    public class jsonAttribute : Attribute
    {
        public Type jsontype { get; set; }
        public jsonAttribute(Type type = null)
        {
            if (type != null)
                jsontype = type;
            else
                jsontype = typeof(BaseJson);
        }
        
        object _instance = null;
        public object instance
        {
            get
            {
                if (_instance == null)
                    _instance = jsontype.Assembly.CreateInstance(jsontype.FullName, false);
                return _instance;
            }
        }
    }

    //[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
    //public class menuAttribute : Attribute,IComparable
    //{
    //    public menuAttribute(string title)
    //    { this.title = title; }

    //    [Obsolete("已经过期，不能使用",true)]
    //    public menuAttribute()
    //    { 
            
    //    }
    //    /// <summary>
    //    /// 菜单名称
    //    /// </summary>
    //    public string menuname { get; set; }

    //    /// <summary>
    //    /// 小图片
    //    /// </summary>
    //    public string tupian { get; set; }

    //    /// <summary>
    //    /// 顺序
    //    /// </summary>
    //    public int paixu { get; set; }

    //    /// <summary>
    //    /// 上级
    //    /// </summary>
    //    public string shangji { get; set; }

    //    /// <summary>
    //    /// 显示的名称
    //    /// </summary>
    //    public string title { get; set; }

    //    /// <summary>
    //    /// 菜单id
    //    /// </summary>
    //    public string caidanid { get; set; }

    //    /// <summary>
    //    /// 路径
    //    /// </summary>
    //    public string actionpath { get; set; }

    //    public int CompareTo(object obj)
    //    {
    //        return (obj as menuAttribute).paixu > this.paixu ? 1 : 0;
    //    }
    //}

    ///// <summary>
    ///// 权限属性
    ///// </summary>
    //[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
    //public class powerAttribute : Attribute
    //{
    //    public powerAttribute(string title, string menuname)
    //    {
    //        this.menuname = menuname;
    //        this.title = title; 
    //    }
    //    [Obsolete("已经过期，不能使用",true)]
    //    public powerAttribute()
    //    {  }
    //    /// <summary>
    //    /// 权限名称
    //    /// </summary>
    //    public string title { get; set; }

    //    /// <summary>
    //    /// 权限标示
    //    /// </summary>
    //    public string powername { get; set; }
        
    //    /// <summary>
    //    /// 菜单标示
    //    /// </summary>
    //    public string menuname { get; set; }
        
    //    /// <summary>
    //    /// 验证权限和菜单是否符合要求
    //    /// </summary>
    //    public void checkvalidate()
    //    {
    //        if (!menuname.ToUpper().StartsWith("M@", StringComparison.Ordinal)) throw new Exception("006:菜单ID必须是'M@'开头的字符串");
    //        if (menuname.Split('@').Length != 3) throw new Exception("007:权限ID必须是'M@CCC@AAA'规则的字符串");
    //    }
    //}

    ///// <summary>
    ///// 可以依赖菜单 依赖权限
    ///// </summary>
    //[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
    //public class yilaiAttribute : Attribute
    //{
    //    /// <summary>
    //    /// 
    //    /// </summary>
    //    /// <param name="powername"></param>
    //    public yilaiAttribute(string powername)
    //    { this.powername = powername; }
    //    /// <summary>
    //    /// 
    //    /// </summary>
    //    public string powername { get; set; }

    //    /// <summary>
    //    /// 
    //    /// </summary>
    //    public void checkvalidate()
    //    {
    //        if (!
    //            (powername.ToUpper().StartsWith("P@", StringComparison.Ordinal) || powername.ToUpper().StartsWith("M@", StringComparison.Ordinal))
    //            ) throw new Exception("004:权限ID必须是'P@','M@'开头的字符串");
    //        if (powername.Split('@').Length != 3) throw new Exception("005:权限ID必须是'P@CCC@AAA'规则的字符串");
    //    }
    //}
}
